package com.shyroke.service;

import java.util.List;

import org.apache.cxf.frontend.ClientProxy;
import org.apache.cxf.interceptor.LoggingInInterceptor;
import org.apache.cxf.interceptor.LoggingOutInterceptor;

import com.shyroke.interceptor.MyHeaderInterceptor;

public class Client {
	public static void main(String[] args) {
		ILogin login=new ILoginService().getILoginPort();
		
		org.apache.cxf.endpoint.Client client=ClientProxy.getClient(login);
		
		/**
		 * LoggingInInterceptor该拦截器类会在客户端被调用前打印日志
		 * LoggingOutInterceptor该拦截器类会在客户端被调用后打印日志
		 */
		client.getInInterceptors().add(new LoggingInInterceptor());
		client.getOutInterceptors().add(new LoggingOutInterceptor());
		
		/**
		 * 客户端请求服务端的方法的时候要先加用户名密码以供服务端验证
		 */
		client.getOutInterceptors().add(new MyHeaderInterceptor("admin1","123"));
		
		MyRoleArray roles=login.getRoles();
		List<MyRole> roleList= roles.item;
		for(MyRole role:roleList) {
			System.out.println(role.getKey());
			for(Role r:role.getValue()) {
				System.out.println(r.getId()+"\t"+r.getRoleName());
			}
			System.out.println("------------------");
		}
	}
}
